package com.shelpe.services.scheduler.item.creative;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.SkipListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shelpe.services.scheduler.po.Adgroups;
import com.shelpe.services.scheduler.po.SyncLog;
import com.shelpe.services.scheduler.repository.SyncLogRepository;
import com.shelpe.services.scheduler.util.Util;

@Component("creativeSkipListener")
public class CreativeSkipListener implements SkipListener<Adgroups, SyncLog>{

	private static final Logger logger = LoggerFactory.getLogger(CreativeSkipListener.class);
	
	@Autowired 
	private SyncLogRepository syncLogRep;
	
	@Override
	public void onSkipInRead(Throwable t) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSkipInWrite(SyncLog item, Throwable t) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSkipInProcess(Adgroups item, Throwable t) {
		// TODO Auto-generated method stub
		logger.info(">>>CreativeSkipListener, error: {}", t);
		SyncLog log = new SyncLog();
		Util.buildExceptionSyncLog(log, item.getUserId(), "syncCreative", t);
		log.setCampaignId(item.getCampaignId());
		log.setAdgroupId(item.getAdgroupId());
		syncLogRep.save(log);
	}

}
